package cn.cherish.feign;

import cn.cherish.config.FeignLogConfig;
import cn.cherish.domain.User;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@FeignClient(value = "user-server" ,configuration = FeignLogConfig.class, fallbackFactory = UserFeignClientFallbackFactory.class)
public interface PayFeign {
    @GetMapping("/findById/{id}")
    User getById(@PathVariable("id") Long id);
}
@Component
class UserFeignClientFallbackFactory implements FallbackFactory<PayFeign> {


    @Override
    public PayFeign create(Throwable throwable) {
        return new PayFeign() {
            @Override
            public User getById(Long id) {
                //把异常信息打印到控制台
                throwable.printStackTrace();

                return new User(-1L,"无此用户","用户服务不可用");
            }
        };
    }
}
